// Copyright (C) 2022 Linlexiao
#ifndef PROBLEM_H
#define PROBLEM_H

#include <QMap>
#include <QRandomGenerator>

#include "calculate.h"
#include "pai.h"

class Problem {
 public:
    void calculateResult();
    Problem() = default;
    Problem(const QString& s, bool& ok);
    QString toString();
    QVector<Pai> hand;
    Pai agariPai{};
    QVector<Block> furu;
    QVector<Pai> dora, ura;
    HandFlags flag;
    Result ans;

 private:
    static const char sep1 = '!';
    static const char sep2 = '@';
};

class ProblemGenerator {
 public:
    ProblemGenerator();
    Problem generate();

 private:
    QVector<Pai> _generateTanyaoBlock();
    QVector<Pai> _generateYakuhaiBlock();
    QVector<Pai> _generateRandomBlock();
    QVector<Pai> _generateTanyaoPair();
    QVector<Pai> _generateYakuhaiPair();
    QVector<Pai> _generateRandomPair();
    Block _generateRandomFuru();
    Block _generateTanyaoFuru();
    Block _generateYakuhaiFuru();
    Pai _getRandomPai();
    bool _canGetPai(PaiType tp, int n, int cnt = 1);
    Pai _getPai(PaiType tp, int n);
    bool _testChance(double chance);
    int doraCnt{};
    int paiLeft[50]{};
    int akaDoraLeft[10]{};
    Wind field, seat;
    Calculator c;
    const double tsumoChance = 0.4;          //自摸概率
    const double callChance = 0.5;           //鸣牌概率
    const double riichiChance = 0.2;         //门前状态下 立直概率
    const double doubleRiichiChance = 0.01;  //立直状态下 双立直概率
    const double ippastsuChance = 0.01;      //立直状态下 一发概率
    const double haiteiHouteiChance = 0.01;  //自摸/荣和情况下 海底/河底概率
    const double rinnshannKaihouChance = 0.01;  //自摸岭上开花概率
    const double chankanChance = 0.01;          // 荣和抢杠概率
    const double kokushiChance = 0.01;          //国士无双概率
    const double chituiChance = 0.05;           //七对子概率

    const double akaDoraChance = 0.25;  //有红宝牌剩余的情况下，得到红宝牌的概率
    const double tripletChance = 0.15;   //刻子概率
    const double quadChance = 0.1;       //刻子成为杠子的概率
    const double closeQuadChance = 0.4;  //杠成为暗杠的概率
};

#endif  // PROBLEM_H
